package job;

import java.io.File;
import java.util.Map;

import models.DrCase;
import models.SystemParams;

import org.apache.commons.lang.StringUtils;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

import play.Play;
import play.jobs.Job;
import play.jobs.On;
import services.CaseService;
import services.SystemParamService;
import utils.BizConstants;
import utils.ShellUtil;
import vos.ResultVo;
import vos.ReturnCode;

/**
 * 重启asr
 * @author wangshaoming
 *
 */
@On("cron.tonight")
public class RestartAsrJob extends Job {
	public static final Logger shelllog=LoggerFactory.getLogger("shell");
	@Override
	public void doJob(){
		SystemParams param=SystemParamService.getById("ReStartAsr_Today");
		if(param==null){
			return;
		}
		if(StringUtils.isEmpty(param.getParamvalue())){
			return;
		}
		if(!"true".equals(param.getParamvalue())){
			return;
		}
		String asrShell=SystemParamService.getValueByCacheId(BizConstants.PARAM_MAP.get("SSH_RESTART_ASR_SHELL"));
		String asrip=SystemParamService.getValueByCacheId(BizConstants.PARAM_MAP.get("SSH_RESTART_ASR_IP"));
		String asruser=SystemParamService.getValueByCacheId(BizConstants.PARAM_MAP.get("SSH_RESTART_ASR_USER"));
		String asrpass=SystemParamService.getValueByCacheId(BizConstants.PARAM_MAP.get("SSH_RESTART_ASR_PASS"));
		String shellTxt="cd "+asrShell+"&& ./restart_asr.sh";
		shelllog.info("自动重启语音识别引擎执行命令为："+shellTxt);
		//调用清空接口
		Map<String,Object> shellMap=ShellUtil.execAndPass(asrip,asruser,asrpass,shellTxt);
		if(shellMap==null){
			shelllog.info("自动重启语音识别引擎失败，未知错误");
		}
		int shellStatus=(int)shellMap.get("status");
		if(shellStatus!=0){
			shelllog.info("自动重启语音识别引擎失败,错误输出为："+(String)shellMap.get("outErr"));
		}
	}
}
